"use strict";
/* Controllers */
app.controller("yarnWhiteAddController", ['$scope', '$location', '$rootScope', '$routeParams', 'yarnWhiteAddService', function ($scope, $location, $rootScope, $routeParams, yarnWhiteAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果ID!=0为更新

    var errorFn = function (result) {
        alert(result);
    };

    $scope.setYarnWhite = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id,
            clusterName: vm.p.clusterName,
            queue: vm.p.queue,
            accountID: vm.p.accountID,
            jobName: vm.p.jobName,
            expireDate: vm.p.expireDate,
            ownerID: vm.p.ownerID
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //window.location = "#/star/yarnWhite/yarnWhite_list";
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        yarnWhiteAddService.setYarnWhite(params, procFn, errorFn);
    };
    $scope.getYarnWhite = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //vm.p = JSON.stringify(response.data);
                vm.p = response.data;
            } else {
                alert(response.msg);
            }
        };
        yarnWhiteAddService.getYarnWhite(params, procFn, errorFn);
    };

    //
    if(vm.p.id!=0) {
        $scope.getYarnWhite();
    }
}]);


/* Services */
app.service('yarnWhiteAddService', ['ajaxService', function (ajaxService) {

    this.setYarnWhite = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/yarn_white/setYarnWhite.do", successFunction, errorFunction);
    };
    this.getYarnWhite = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/yarn_white/getYarnWhite.do", successFunction, errorFunction);
    };
}]);

